<?php

namespace app\service\shopify\action\graph;

class ProductGraph extends GraphQLBase
{
    public function getProductList(int $first)
    {
        $query = <<<QUERY
query getProducts(\$first: Int) {
  products(first: \$first) {
      nodes {
        title
        id
        media(first: 1) {
        nodes {
          preview{
          image{
            url
          }
          }
        }
      }
        priceRangeV2{
        maxVariantPrice{
        amount
        currencyCode
        }
        minVariantPrice{
        amount
        currencyCode
        }
        }
      }
    }
}
QUERY;
        $variables = [
            'first'=>$first
        ];
        return $this->post($query,$variables);
    }


    public function product(string $ownerId)
    {
        $query = <<<QUERY
query getProduct(\$ownerId: ID!) {
  product(id: \$ownerId) {
      title
      id
      description
      descriptionHtml
      options(first: 99){
           name
           values
      }
      media(first: 99) {
        nodes {
          preview{
          image{
            url
          }
          }
        }
      }
      variants(first: 99) {
        nodes {
          barcode
          id
          title
          price
          sku
          unitPrice{
          amount
          currencyCode
          }
          image(scale: 1){
          url
          }
        }
      }
    }
  }
QUERY;
        return $this->post($query,['ownerId'=>sprintf('gid://shopify/Product/%s',$ownerId)]);
    }
}